package com.vmix.vmixmobiledemo;

import com.vmix.vmixmobiledemo.VmixCollectionListAdapter;
import com.vmix.vmixmobiledemo.BrowseVideosActivity;

import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TabHost;
import android.widget.TextView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.ServiceConnection;
import android.content.res.Resources;


import android.app.Activity;
import android.app.TabActivity;
import android.os.Bundle;
import android.os.IBinder;

// import vmixsdk collections service
import com.vmix.android.vmixsdk.rds.GetCollectionsService;
import com.vmix.android.vmixsdk.valueobject.VmixCollections;

public class MainActivity extends TabActivity {
    /** Called when the activity is first created. */
	
	ListView list;
	VmixCollectionListAdapter adapter;
	
	// tabhost initialized to null
	private TabHost tabHost = null;
	
	// private vmix collections
	// private VmixCollections collections;
	// intent filter for the getCollections message
	// private IntentFilter filter = null;
	// intent receiver
	// private GetCollectionsReceiver receiver = null;
	// service reference
	// private GetCollectionsService serviceBinder = null;
	
    /**
     * Handle the connections between the service and activity
     */
    /*private ServiceConnection serviceConnection = new ServiceConnection() {
		
		@Override
		public void onServiceDisconnected(ComponentName className) {
			// TODO Auto-generated method stub
			serviceBinder = null;
		}
		
		@Override
		public void onServiceConnected(ComponentName className, IBinder service) {
			
			serviceBinder = (( GetCollectionsService.GetCollectionsBinder) service).getService();
		
		}
	};
	*/
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setDefaultKeyMode( Activity.DEFAULT_KEYS_SEARCH_LOCAL );

        // window features
        requestWindowFeature( Window.FEATURE_INDETERMINATE_PROGRESS );
        
        setContentView(R.layout.main);
    
        // initialize tabset
        this.initializeTabs();

    }
      
    
    @Override
    public void onDestroy()
    {
    	super.onDestroy();

		// unregister receiver
		//unregisterReceiver(this.receiver);

    }
        
    /**
     * initialize the tabset on main activity
     * 
     */
    private void initializeTabs()
    {
    	if( this.tabHost != null ) {
    		throw new IllegalStateException("Trying to intialize already initializd TabHost");
    	}
    	
    	Resources res = getResources();
    	
    	this.tabHost = getTabHost();	// get tabhost
    	TabHost.TabSpec tabSpec = null;	// initialize tab spec
    	Intent tabIntent = null; 		// define tab intent
    	
    	View tab1 = LayoutInflater.from(this).inflate(R.layout.vmix_tab_layout, null);
        ImageView iv = (ImageView) tab1.findViewById(R.id.vmixTabImageView);
        iv.setImageResource(R.drawable.lookup_icon_gray_48);
        TextView tv = (TextView) tab1.findViewById(R.id.vmixTabTextView);
        tv.setText("Browse");
        
    	View tab2 = LayoutInflater.from(this).inflate(R.layout.vmix_tab_layout, null);
        ImageView iv2 = (ImageView) tab2.findViewById(R.id.vmixTabImageView);
        iv2.setImageResource(R.drawable.upload_icon_gray_48);
        TextView tv2 = (TextView) tab2.findViewById(R.id.vmixTabTextView);
        tv2.setText("Upload");
    
    	// Create an intent for the collections activity
    	tabIntent = new Intent().setClass(this, CollectionsActivity.class );
    	
    	//tabSpec = tabHost.newTabSpec("browse").setIndicator("Browse", res.getDrawable( R.drawable.ic_menu_gallery )) .setContent(tabIntent);
    	tabSpec = tabHost.newTabSpec("browse").setIndicator(tab1).setContent(tabIntent); 
    	
    	tabHost.addTab(tabSpec);

    	// Create an intent for the upload activity
    	
    	tabIntent = new Intent().setClass(this, UploadActivity.class );
    	
    	//tabSpec = tabHost.newTabSpec("upload").setIndicator("Upload", res.getDrawable( R.drawable.upload )).setContent(tabIntent);
    	tabSpec = tabHost.newTabSpec("upload").setIndicator(tab2).setContent(tabIntent);
    	tabHost.addTab(tabSpec);
    
    	// set current tab
    	tabHost.setCurrentTab(0);
    }
	
}